package com.accp.action;

import java.io.InputStream;
import java.io.UnsupportedEncodingException;

import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class DownloadAction extends ActionSupport {
	private String fileName;// 初始的通过param指定的文件名属性   

	public InputStream getInputStream() throws Exception {
		// 通过 ServletContext，也就是application 来读取数据   
		return ServletActionContext.getServletContext().getResourceAsStream(fileName);

	}

	public String execute() throws Exception {
		return SUCCESS;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	/** 提供转换编码后的供下载用的文件名 */
	public String getDownloadFileName() {
		String downFileName = fileName;
		try {
			downFileName = new String(downFileName.getBytes(), "ISO8859-1");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}

		return downFileName;

	}
}
